(function() {
	/*
	 * Title-Map
	 */
	eventManager.after("AppReady", function() {
		var _set_title = Path.setTitle;
		Path.setTitle = function() {
			App.set("$Loc.document_title", _set_title());
		};
		App.set("$Loc.document_title", Path.document_title);
	});
	// 接口地址
	var api_root = "http://121.40.72.93:4100/qaq";
	window.public_api = {
		admin: {
			login: api_root + "/admin/login",
			loginer: api_root + "/admin/loginer",
			create: api_root + "/admin/create",
			loginout: api_root + "/admin/loginout"
		},
		section: {
			get: {
				byid: api_root + "/section/by_id/:section_id/with_news_list",
				list_all: api_root + "/section/list_all"
			},
			create: api_root + "/section/create",
			update: api_root + "/section/update",
			remove: api_root + "/section/remove/"
		},
		news: {
			get: {
				detail_by_id: api_root + "/news/detail_by_id/",
				list_by_section_id: api_root + "/news/list_by_section_id/",
				list_all: api_root + "/news/list_all"
			},
			create: api_root + "/news/create",
			update: api_root + "/news/update",
			remove: api_root + "/news/remove/"
		},
		banner: {
			get: {
				all: api_root + "/banner/all"
			},
			create: api_root + "/banner/create",
			update: api_root + "/banner/update",
			remove: api_root + "/banner/remove/"
		}
	};
	// 工具类
	// 上传图片
	window.upload_image = function(file, dtd) {
		require(["/js/tools/image_upload.js"], function(image_upload) {
			image_upload(file, function(err, precentComplete, url) {
				if (precentComplete == 1) {
					dtd.resolve(url);
					console.log("url,", url)
					alert("success", "上传成功");
				};
			});
		});
		return dtd;
	};
	Path.on("*", function(_current_location) {
		console.log("_current_location:", _current_location);
		// 获取已登陆用户
		if (Path._current_page.toString()
			.indexOf("/login") < 0) {
			coAjax._ajax(public_api.admin.loginer, "get", {}, function(r) {})
				.then(function(r) {
					App.set("loginer", r.info);
					eventManager.emitAfter("admin_login_success");
				});
		};
	});
}());
